package com.pjj.transactionservice.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pjj.transactionservice.Entity.Result;
import com.pjj.transactionservice.Entity.Transaction;
import com.pjj.transactionservice.mapper.TransactionMapper;
import com.pjj.transactionservice.service.TransactionService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.sql.Timestamp;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 76004
 * @apiNote
 * @date 2023/1/18 11:57
 */
@RestController
@RequestMapping("/transaction")
@CrossOrigin
public class TransactionController {
    @Autowired
    TransactionMapper transactionMapper;

    @Autowired
    TransactionService transactionService;

    @GetMapping("")
    public ModelAndView showTransactionPage(){
        return new ModelAndView("Menu/index");
    }


    @ApiOperation(value = "查询所有交易")
    @GetMapping("/selectAll")
    public Object selectAllTransaction(int pageNum, int pageSize){
        return transactionService.selectPage(pageNum,pageSize);
    }

    @ApiOperation(value = "按照id查询交易")
    @GetMapping("/selectById")
    public Object selectById(long transactionId){
        return transactionService.selectById(transactionId);
    }

    @ApiOperation(value = "添加交易")
    @PostMapping("/insertTransaction")
    public Object insertTransaction(@RequestBody Transaction transaction){
        return transactionService.insertTransaction(transaction);
    }

    @ApiOperation(value = "更新交易")
    @PutMapping("/updateTransaction")
    public Object updateTransaction(@RequestBody Transaction transaction){
        return transactionService.updateTransaction(transaction);
    }

    @ApiOperation(value = "按照id删除交易")
    @DeleteMapping("/deleteTransactionById")
    public Object deleteTransactionById(long transactionId){
        return transactionService.deleteById(transactionId);
    }

    @GetMapping("/test")
    public Object test(){
        Map<String,Object>map = new HashMap<>();
        map.put("123","123");
        return map;
    }

    @ApiOperation(value = "查询交易总数")
    @GetMapping("/selectTransactionCount")
    public Object selectCount(){
        return transactionService.selectCount();
    }

    @ApiOperation(value = "按照status查询交易")
    @GetMapping("/selectByStatus")
    public Object selectByStatus(int status,int pageNum,int pageSize){
        return transactionService.selectByStatus(status,pageNum,pageSize);
    }

    @ApiOperation(value = "按照status查询交易数量")
    @GetMapping("/selectCountByStatus")
    public Object selectCountByStatus(int status){
        return transactionService.selectCountByStatus(status);
    }


}
